import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsEmail, IsOptional, MinLength, MaxLength, IsInt, IsIn } from 'class-validator';
import { ICreateUser, USER_STATUS_VALUES } from '@nbase/shared';
import { Type } from 'class-transformer';

/**
 * 创建用户 DTO
 * 实现 shared 中的接口，添加运行时验证
 */
export class CreateUserDto implements ICreateUser {
  @ApiProperty({
    description: '用户名',
    example: 'zhangsan',
    minLength: 3,
    maxLength: 50,
  })
  @IsString()
  @MinLength(3)
  @MaxLength(50)
  username!: string;

  @ApiProperty({
    description: '密码',
    example: 'password123',
    minLength: 6,
    maxLength: 512,
  })
  @IsString()
  @MinLength(6)
  @MaxLength(512)
  password!: string;

  @ApiPropertyOptional({
    description: '昵称',
    example: '张三',
    maxLength: 50,
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  nickname?: string;

  @ApiPropertyOptional({
    description: '邮箱',
    example: 'zhangsan@example.com',
    maxLength: 50,
  })
  @IsEmail()
  @IsOptional()
  @MaxLength(50)
  email?: string;

  @ApiPropertyOptional({
    description: '手机号',
    example: '13800138000',
    maxLength: 50,
  })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  mobile?: string;

  @ApiPropertyOptional({
    description: '头像URL',
    example: 'https://example.com/avatar.jpg',
    maxLength: 512,
  })
  @IsString()
  @IsOptional()
  @MaxLength(512)
  avatar?: string;

  @ApiPropertyOptional({
    description: '状态（1.启用 2.禁用）',
    example: 1,
    enum: USER_STATUS_VALUES,
  })
  @Type(() => Number)
  @IsInt()
  @IsIn(USER_STATUS_VALUES)
  status!: number;

  @ApiPropertyOptional({
    description: '部门ID',
  })
  @IsString()
  @IsOptional()
  deptId?: string;

  @ApiPropertyOptional({
    description: '用户描述',
    example: '这是一个测试用户',
    maxLength: 256,
  })
  @IsString()
  @IsOptional()
  @MaxLength(256)
  description?: string;
}

